home *** CD-ROM | disk | FTP | other *** search
/ Clickx 36 / Clickx 36.iso / mac / assets / software / tuxpaint.dmg / Tux Paint.app / Contents / Frameworks / compiler.h next >
Encoding:
C/C++ Source or Header  |  2006-10-20  |  4.0 KB  |  153 lines

  1. /*
  2.   compiler.h
  3.  
  4.   Compiler-specific #defines and such
  5.   for Tux Paint
  6.  
  7.   Mostly by Albert Cahalan <albert@users.sf.net>
  8.   Copyright (c) 2002-2006
  9.  
  10.   http://www.newbreedsoftware.com/tuxpaint/
  11.  
  12.   This program is free software; you can redistribute it and/or modify
  13.   it under the terms of the GNU General Public License as published by
  14.   the Free Software Foundation; either version 2 of the License, or
  15.   (at your option) any later version.
  16.  
  17.   This program is distributed in the hope that it will be useful,
  18.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.   GNU General Public License for more details.
  21.  
  22.   You should have received a copy of the GNU General Public License
  23.   along with this program; if not, write to the Free Software
  24.   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  25.   (See COPYING.txt)
  26.  
  27.   June 14, 2002 - February 18, 2006
  28.   $Id: compiler.h,v 1.5 2006/08/27 21:00:55 wkendrick Exp $
  29. */
  30.  
  31. #ifdef WIN32
  32. /* Horrible, dangerous macros. */
  33. /*
  34.   The SDL stderr redirection trick doesn't seem to work for perror().
  35.   This does pretty much the same thing.
  36. */
  37. #define perror(str) ({ \
  38.   if ( (str) && *(str) ) \
  39.     fprintf(stderr,"%s : ",(str)); \
  40.   fprintf(stderr, \
  41.           "%s [%d]\n", \
  42.           (errno<_sys_nerr)?_sys_errlist[errno]:"unknown",errno ); \
  43. })
  44.  
  45. /*
  46.   MinGW implementation of isspace() crashes on some Win98 boxes
  47.   if c is 'out-of-range'.
  48. */
  49. #define isspace(c) (((c) == 0x20) || ((c) >= 0x09 && (c) <= 0x0D))
  50.  
  51. /*
  52.   WIN32 and MINGW don't have strcasestr().
  53. */
  54. #define NOMINMAX
  55. #include "Shlwapi.h"
  56. #define strcasestr StrStrI
  57. #endif /* WIN32 */
  58.  
  59.  
  60.  
  61.  
  62. #ifdef __GNUC__
  63. // This version has strict type checking for safety.
  64. // See the "unnecessary" pointer comparison. (from Linux)
  65. #define min(x,y) ({ \
  66.   typeof(x) _x = (x);     \
  67.   typeof(y) _y = (y);     \
  68.   (void) (&_x == &_y);            \
  69.   _x < _y ? _x : _y; })
  70. #define max(x,y) ({ \
  71.   typeof(x) _x = (x);     \
  72.   typeof(y) _y = (y);     \
  73.   (void) (&_x == &_y);            \
  74.   _x > _y ? _x : _y; })
  75. #else
  76. #define min(a,b) (((a) < (b)) ? (a) : (b))
  77. #define max(a,b) (((a) > (b)) ? (a) : (b))
  78. #endif
  79.  
  80. #define clamp(lo,value,hi)    (min(max(value,lo),hi))
  81.  
  82.  
  83. // since gcc-2.5
  84. #ifdef __GNUC__
  85. #define NORETURN __attribute__((__noreturn__))
  86. #define FUNCTION __attribute__((__const__))    // no access to global mem, even via ptr, and no side effect
  87. #else
  88. #define NORETURN
  89. #define FUNCTION
  90. #endif
  91.  
  92. #if !defined(restrict) && __STDC_VERSION__ < 199901
  93. #if __GNUC__ > 2 || __GNUC_MINOR__ >= 92
  94. #define restrict __restrict__
  95. #else
  96. #warning No restrict keyword?
  97. #define restrict
  98. #endif
  99. #endif
  100.  
  101.  
  102. #if __GNUC__ > 2 || __GNUC_MINOR__ >= 96
  103. // won't alias anything, and aligned enough for anything
  104. #define MALLOC __attribute__ ((__malloc__))
  105. // no side effect, may read globals
  106. #ifndef WIN32
  107. #define PURE __attribute__ ((__pure__))
  108. #endif
  109. // tell gcc what to expect:   if(unlikely(err)) die(err);
  110. #define likely(x)       __builtin_expect(!!(x),1)
  111. #define unlikely(x)     __builtin_expect(!!(x),0)
  112. #define expected(x,y)   __builtin_expect((x),(y))
  113. #else
  114. #define MALLOC
  115. #define PURE
  116. #define likely(x)       (x)
  117. #define unlikely(x)     (x)
  118. #define expected(x,y)   (x)
  119. #endif
  120.  
  121.  
  122. #ifdef __powerpc__
  123. // Ticks at 1/4  the memory bus clock (24.907667 MHz on Albert's Mac Cube)
  124. // This is good for 80-second diff or 160-second total.
  125. #define CLOCK_ASM(tbl) asm volatile("mftb %0" : "=r" (tbl))
  126. #define CLOCK_TYPE unsigned long
  127. #ifndef CLOCK_SPEED
  128. // #warning Benchmark times are based on a 99.63 MHz memory bus.
  129. #define CLOCK_SPEED 24907667.0
  130. #endif
  131. #endif
  132.  
  133. #ifdef __i386__
  134. #define CLOCK_ASM(tbl) asm volatile("rdtsc" : "=A" (tbl))
  135. #define CLOCK_TYPE unsigned long long
  136. #ifndef CLOCK_SPEED
  137. // #warning Benchmark times are based on a 450 MHz CPU.
  138. #define CLOCK_SPEED 450000000.0
  139. #endif
  140. #endif
  141.  
  142. #ifndef CLOCK_ASM
  143. // #warning No idea how to read CPU cycles for you, sorry.
  144. #define CLOCK_ASM(tbl)
  145. #define CLOCK_TYPE unsigned long
  146. #define CLOCK_SPEED 1000000000.0
  147. #endif
  148.  
  149. #ifdef NO_ASM
  150. #undef CLOCK_ASM
  151. #define CLOCK_ASM(x) x=42
  152. #endif
  153.